package view;

import java.awt.Desktop;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.OutputStream;

import control.ToWaJoJopoly;
/**
 * Opens a pdf viewer to show the help
 * 
 * @author Thomas
 *
 */
public class Help 
{

	public Help() 
	{
		/* try {
			 
				if ((new File("Team Documents/Spielregeln.pdf")).exists()) {
		 
					Process p = Runtime
					   .getRuntime()
					   .exec("rundll32 url.dll,FileProtocolHandler Team Documents\\Spielregeln.pdf");
					p.waitFor();
		 
				} else {
		 
					System.out.println("File does not exist");
		 
				}
		 
				System.out.println("Done");
		 
		  	  } catch (Exception ex) {
				ex.printStackTrace();
			  }*/
		
		
		 try 
		 {
			
			 File pdfFile = new File("Spielregeln.pdf");
			 
			 if (!pdfFile.exists()) 
			 {
			 
				 BufferedInputStream pdfInput= new BufferedInputStream(ToWaJoJopoly.class.getResourceAsStream("/Spielregeln.pdf"));
				 BufferedOutputStream pdfOutput = new BufferedOutputStream(new FileOutputStream("Spielregeln.pdf"));
			
				 byte[] buffer = new byte[4096];
				 int length;
			
				 while( (length = pdfInput.read(buffer)) > 0)
				 {
					 pdfOutput.write(buffer, 0, length);
				 }
			
				 pdfOutput.flush();
			
				 pdfInput.close();
				 pdfOutput.close();
			 }
			
			 Desktop.getDesktop().open(pdfFile);
			 
			/*if (Desktop.isDesktopSupported()) 
			{
					Desktop.getDesktop().open(pdfFile);
			} 
			else 
			{
				System.out.println("Awt Desktop is not supported!");
			}*/
		 
			 
			
			 System.out.println("Done");
		 
			  
		  } 
		  catch (Exception ex) 
		  {
			 ex.printStackTrace();
		  }
	}
}
